import QtQuick 2.6
import QtQuick.Layouts 1.3

import Qt.labs.controls 1.0
import QtQuick.XmlListModel 2.0
import "../template" as Template
import "../js/MemberRegisterNavigator.qml.js" as Jit

Template.Navigator {
    id: nav
    title: "账号注册"


        GridLayout {
            anchors.centerIn: parent

            rowSpacing: 12

            columns: 2

            Label {
                text: "姓名"
                Layout.alignment: Qt.AlignRight
                font.pixelSize: 15
            }

            TextField {
                id: nameTxt
                Layout.alignment: Qt.AlignLeft
                maximumLength: 4
            }



            Label {
                text: "密码"
                Layout.alignment: Qt.AlignRight
                font.pixelSize: 15
            }

            TextField {
                id: passwordTxt

                echoMode: TextInput.Password
                Layout.alignment: Qt.AlignLeft
                maximumLength: 12
            }

            Label {
                text: "再输一次"
                Layout.alignment: Qt.AlignRight
                font.pixelSize: 15
            }
            TextField {
                id: passText
                Layout.alignment: Qt.AlignLeft
                maximumLength: 32
                echoMode: TextInput.Password
            }

            Label {
                text: "手机"
                Layout.alignment: Qt.AlignRight
                font.pixelSize: 15
            }

            TextField {
                id: mobileTxt
                Layout.alignment: Qt.AlignLeft
                maximumLength: 11
            }


            Label {
                text: "邮箱"
                Layout.alignment: Qt.AlignRight
                font.pixelSize: 15
            }

            TextField {
                id: mailTxt


                Layout.alignment: Qt.AlignLeft
                maximumLength: 32
            }

            Label {
                text: qsTr("驾校")
                verticalAlignment: Text.AlignVCenter
                height: listSchool.height
            }

            ComboBox {
                id: listSchool


                model: XmlListModel {
                    id: model_School

                    source: http.build("/school.xml", {})
                    query: "/schools/school"

                    XmlRole { name: "id"; query: "id/string()" }
                    XmlRole { name: "name"; query: "name/string()" }

                    onStatusChanged: {
                        if (status == XmlListModel.Ready) {
                             modelTeacher.source = http.build("/member.xml?t=t&school=" + model_School.get(listSchool.currentIndex).id,{})
                             console.log("source:", modelTeacher.source)
                        }
                    }

                }
                currentIndex: 0
                textRole: "name"
                width: passwordTxt.width
            }

            Label {
                text: "教练"
                Layout.alignment: Qt.AlignRight
                font.pixelSize: 15
                height: listTeacher.height
            }

            ComboBox {
                id: listTeacher
                Layout.alignment: Qt.AlignLeft

                model: XmlListModel {
                    id: modelTeacher


                    query: "/members/member"

                    XmlRole { name: "id"; query: "id/string()" }
                    XmlRole { name: "name"; query: "name/string()" }

                }
                textRole: "name"

                currentIndex: 0


            }

            Button {
                Layout.columnSpan: 2
                Layout.alignment: Qt.AlignHCenter
                Layout.preferredWidth: implicitWidth * 1.5
                text: "注册"
                onClicked: Jit.register()
            }
        }

}
